import 'package:gold/generated/json/base/json_convert_content.dart';
import 'package:gold/model/point_list_model.dart';

PointListModel $PointListModelFromJson(Map<String, dynamic> json) {
  final PointListModel pointListModel = PointListModel();
  final List<PointModel>? data = (json['data'] as List<dynamic>?)?.map(
          (e) => jsonConvert.convert<PointModel>(e) as PointModel).toList();
  if (data != null) {
    pointListModel.data = data;
  }
  final int? total = jsonConvert.convert<int>(json['total']);
  if (total != null) {
    pointListModel.total = total;
  }
  final int? count = jsonConvert.convert<int>(json['count']);
  if (count != null) {
    pointListModel.count = count;
  }
  final int? perPage = jsonConvert.convert<int>(json['per_page']);
  if (perPage != null) {
    pointListModel.perPage = perPage;
  }
  final int? currentPage = jsonConvert.convert<int>(json['current_page']);
  if (currentPage != null) {
    pointListModel.currentPage = currentPage;
  }
  final int? totalPages = jsonConvert.convert<int>(json['total_pages']);
  if (totalPages != null) {
    pointListModel.totalPages = totalPages;
  }
  return pointListModel;
}

Map<String, dynamic> $PointListModelToJson(PointListModel entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['data'] = entity.data?.map((v) => v.toJson()).toList();
  data['total'] = entity.total;
  data['count'] = entity.count;
  data['per_page'] = entity.perPage;
  data['current_page'] = entity.currentPage;
  data['total_pages'] = entity.totalPages;
  return data;
}

extension PointListModelExtension on PointListModel {
  PointListModel copyWith({
    List<PointModel>? data,
    int? total,
    int? count,
    int? perPage,
    int? currentPage,
    int? totalPages,
  }) {
    return PointListModel()
      ..data = data ?? this.data
      ..total = total ?? this.total
      ..count = count ?? this.count
      ..perPage = perPage ?? this.perPage
      ..currentPage = currentPage ?? this.currentPage
      ..totalPages = totalPages ?? this.totalPages;
  }
}

PointModel $PointModelFromJson(Map<String, dynamic> json) {
  final PointModel pointModel = PointModel();
  final int? id = jsonConvert.convert<int>(json['id']);
  if (id != null) {
    pointModel.id = id;
  }
  final int? userId = jsonConvert.convert<int>(json['user_id']);
  if (userId != null) {
    pointModel.userId = userId;
  }
  final int? points = jsonConvert.convert<int>(json['points']);
  if (points != null) {
    pointModel.points = points;
  }
  final int? currentAmount = jsonConvert.convert<int>(json['current_amount']);
  if (currentAmount != null) {
    pointModel.currentAmount = currentAmount;
  }
  final String? reason = jsonConvert.convert<String>(json['reason']);
  if (reason != null) {
    pointModel.reason = reason;
  }
  final int? orderId = jsonConvert.convert<int>(json['order_id']);
  if (orderId != null) {
    pointModel.orderId = orderId;
  }
  final String? createdAt = jsonConvert.convert<String>(json['created_at']);
  if (createdAt != null) {
    pointModel.createdAt = createdAt;
  }
  return pointModel;
}

Map<String, dynamic> $PointModelToJson(PointModel entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['id'] = entity.id;
  data['user_id'] = entity.userId;
  data['points'] = entity.points;
  data['current_amount'] = entity.currentAmount;
  data['reason'] = entity.reason;
  data['order_id'] = entity.orderId;
  data['created_at'] = entity.createdAt;
  return data;
}

extension PointModelExtension on PointModel {
  PointModel copyWith({
    int? id,
    int? userId,
    int? points,
    int? currentAmount,
    String? reason,
    int? orderId,
    String? createdAt,
  }) {
    return PointModel()
      ..id = id ?? this.id
      ..userId = userId ?? this.userId
      ..points = points ?? this.points
      ..currentAmount = currentAmount ?? this.currentAmount
      ..reason = reason ?? this.reason
      ..orderId = orderId ?? this.orderId
      ..createdAt = createdAt ?? this.createdAt;
  }
}